import sys

import matplotlib.pyplot as plt
import numpy as np
import sutils.drawer.chart as chart

if __name__ == "__main__":
    
    task = sys.argv[1]
    fitness = np.load(f"logs/{task}-fitness.npy")
    newfitness = np.load(f"logs/{task}-newFitness.npy")
    
    chart.setFontFamily(chart.FontFamily.ARIAL_UNICODE_MS)
    chart.setAxesUnicodeMinus(False)
    chart.setGrid(True)
    chart.setGridStyle(chart.GridStyle.DASH)
    chart.setTickDirection('x', chart.TickDirection.IN)
    chart.setTickDirection('y', chart.TickDirection.IN)
    chart.setFigureSize([16, 9])
    chart.setTickLabelSize('x', 15)
    chart.setTickLabelSize('y', 15)
    chart.setLegendFontSize(30)
    chart.setAxesLabelSize(30)

    plt.xlabel("训练代数")
    plt.ylabel("适应度值")
    plt.plot(newfitness, label="新子代个体适应度值")
    plt.plot(fitness, label="最优个体适应度值")
    
    plt.savefig(f"{task}.png", bbox_inches='tight')
